//
//  consultDetailsController.m
//  soccer
//
//  Created by 上官千城 on 15/9/4.
//  Copyright (c) 2015年 上官千城. All rights reserved.
//

#import "consultDetailsController.h"

@interface consultDetailsController ()

@end

@implementation consultDetailsController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
   
    
    self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 20, WIDTH, HEIGHT-80)];
    self.webView.backgroundColor = [UIColor whiteColor];
    NSString *str = [NSString stringWithFormat:@"http://mrobot.pcbaby.com.cn/v2/qzbd/askDetail?qId=694234"];
    NSURL *url = [NSURL URLWithString:str];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];
    [self.view addSubview:self.webView];
    
    //tableBarView
    self.tableView = [[UIView alloc]initWithFrame:CGRectMake(0, HEIGHT - 70, WIDTH, 70)];
    self.tableView.userInteractionEnabled = YES;
    self.tableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    
    
    //返回按钮
    UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
//    back.backgroundColor = [UIColor redColor];
    back.frame = CGRectMake(40, 0, 40, 40);
    [back addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [back setImage:[UIImage imageNamed:@"资讯详情页_18@2x"] forState:UIControlStateNormal];
    [self.tableView addSubview:back];
    //分享按钮
    UIButton *share = [UIButton buttonWithType:UIButtonTypeCustom];
    share.frame = CGRectMake(back.frame.origin.x + back.frame.size.width+40, back.frame.origin.y, back.frame.size.width, back.frame.size.height);
//    share.backgroundColor = [UIColor redColor];
    [share setImage:[UIImage imageNamed:@"资讯详情页_18-04@2x"] forState:UIControlStateNormal];
    [share addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
    [self.tableView addSubview:share];
    //评论
    UIButton *comment = [UIButton buttonWithType:UIButtonTypeCustom];
    comment.frame = CGRectMake(share.frame.origin.x + share.frame.size.width + 40, share.frame.origin.y, share.frame.size.width, share.frame.size.height);
//    comment.backgroundColor = [UIColor redColor];
    [comment setImage:[UIImage imageNamed:@"资讯详情页_18-02@2x"] forState:UIControlStateNormal];
    [comment addTarget:self action:@selector(commentAction) forControlEvents:UIControlEventTouchUpInside];
    [self.tableView addSubview:comment];
    //设置
    UIButton *setting = [UIButton buttonWithType:UIButtonTypeCustom];
//    setting.backgroundColor = [UIColor redColor];
    setting.frame = CGRectMake(comment.frame.origin.x + comment.frame.size.width + 40, comment.frame.origin.y, comment.frame.size.width, comment.frame.size.height);
    [setting setImage:[UIImage imageNamed:@"资讯详情页_18-03@2x"] forState:UIControlStateNormal];
    [setting addTarget:self action:@selector(settingAction) forControlEvents:UIControlEventTouchUpInside];
    [self.tableView addSubview:setting];
    //创建评论View
    [self creatCommentText];
    //创建设置View
    [self creatSettingView];
   
}

//创建设置View
-(void)creatSettingView
{
    self.settingOpen = NO;
    //底层
    self.settingView = [[UIView alloc]initWithFrame:CGRectMake(0, HEIGHT, WIDTH, HEIGHT)];
    self.settingView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.settingView];
    //弹出层
    UIView *aView = [[UIView alloc]initWithFrame:CGRectMake(0, HEIGHT -200, WIDTH, 200)];
    aView.backgroundColor = [UIColor whiteColor];
    [self.settingView addSubview:aView];
    
    //底层view 轻拍手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeAction)];
    [self.settingView addGestureRecognizer:tap];
    
    UILabel *fontLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 70, 30)];
    fontLabel.text = @"字体大小";
    [aView addSubview:fontLabel];
    //更改字体按钮
    NSMutableArray *array = [NSMutableArray arrayWithObjects:@"标准",@"大",@"超大", nil];
    UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:array];
    segment.frame = CGRectMake(WIDTH - 120, 10, 100, 30);
    segment.selectedSegmentIndex = 0;
    [segment addTarget:self action:@selector(segmentedButton) forControlEvents:UIControlEventValueChanged];
    [aView addSubview:segment];
    
    UILabel *light = [[UILabel alloc]initWithFrame:CGRectMake(fontLabel.frame.origin.x, fontLabel.frame.origin.y + fontLabel.frame.size.height + 10, 70, 30)];
    light.text = @"屏幕亮度";
    [aView addSubview:light];
    
    UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(WIDTH - 120, light.frame.origin.y, 110, 30)];
    slider.value = 110;
    slider.minimumValue = 1;
    slider.maximumValue = 110.0;
    [aView addSubview:slider];
    //夜间模式
    UILabel *night = [[UILabel alloc]initWithFrame:CGRectMake(light.frame.origin.x, light.frame.origin.y + light.frame.size.height+ 10, 70, 30)];
    night.text = @"夜间模式";
    [aView addSubview:night];
    
    UISwitch *nightSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(WIDTH - 80, night.frame.origin.y, 0, 0)];
    [nightSwitch addTarget:self action:@selector(nightAction) forControlEvents:UIControlEventEditingChanged];
    [aView addSubview:nightSwitch];
    
}

//夜间模式
-(void)nightAction
{
    NSLog(@"222");
}

//更改字体按钮
-(void)segmentedButton
{
    NSLog(@"2");
}


//创建评论View
-(void)creatCommentText
{
    self.open = NO;
    self.commentView = [[UIView alloc]initWithFrame:CGRectMake(0, HEIGHT, WIDTH, HEIGHT-70)];
    self.commentView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.commentView];
    
    //底层view 轻拍手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeAction)];
    [self.commentView addGestureRecognizer:tap];
    
    UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(10, 100, WIDTH - 20, self.view.frame.size.height/3)];
    text.textAlignment = NSTextAlignmentJustified;
    text.placeholder = @"请输入评论信息";
    text.borderStyle = UITextBorderStyleRoundedRect;
    [self.commentView addSubview:text];
    
    UIButton *publish = [UIButton buttonWithType:UIButtonTypeCustom];
//    publish.backgroundColor = [UIColor orangeColor];
    publish.frame = CGRectMake(WIDTH - 100, text.frame.origin.y + text.frame.size.height +10, 80, 30);
    [publish setTitle:@"发布评论" forState:UIControlStateNormal];
    [publish setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [publish addTarget:self action:@selector(publishAction) forControlEvents:UIControlEventTouchUpInside];
    [self.commentView addSubview:publish];
}
//评论推送
-(void)publishAction
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"是否发表评论" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil];
    [alert show];
    

}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
            [UIView animateWithDuration:0.1 animations:^{
                self.commentView.frame = CGRectMake(0, HEIGHT, self.commentView.frame.size.width, self.commentView.frame.size.height);
        
            }];
            self.open = NO;
    }
    else if (buttonIndex == 1)
    {
        
    }
}

//轻拍关闭
-(void)closeAction
{
    [UIView animateWithDuration:0.1 animations:^{
        self.commentView.frame = CGRectMake(0, HEIGHT, self.commentView.frame.size.width, self.commentView.frame.size.height);
        
    }];
    self.open = NO;
    [UIView animateWithDuration:0.1 animations:^{
        self.settingView.frame = CGRectMake(0, HEIGHT, self.settingView.frame.size.width, self.settingView.frame.size.height);
        
    }];
    self.settingOpen = NO;
}

//设置
-(void)settingAction
{
    [UIView animateWithDuration:0.1 animations:^{
        self.settingView.frame = CGRectMake(0, 0 , self.settingView.frame.size.width, self.settingView.frame.size.height);
        
    }];
    self.open = YES;
    
    
}

//分享
-(void)shareAction
{
    NSLog(@"24");
    [UMSocialSnsService presentSnsIconSheetView:self appKey:@"55b055cc67e58eb761006f7a"shareText:@"你要分享的文字"shareImage:[UIImage imageNamed:@"icon.png"]shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,nil]delegate:self];
}

//评论
-(void)commentAction
{
    if (self.open == NO) {
        [UIView animateWithDuration:0.1 animations:^{
            self.commentView.frame = CGRectMake(0, 0, self.commentView.frame.size.width, self.commentView.frame.size.height);
            
        }];
        self.open = YES;
    } else {
        [UIView animateWithDuration:0.1 animations:^{
            self.commentView.frame = CGRectMake(0, HEIGHT, self.commentView.frame.size.width, self.commentView.frame.size.height);
            
        }];
        self.open = NO;
    }

        
}
//返回按钮
-(void)backAction
{
    NSLog(@"2");
    [self.navigationController popViewControllerAnimated:YES];
}

//视图即将显示时候隐藏navbar和tabbar
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
    self.tabBarController.tabBar.hidden = YES;
  
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
